package com.wish.algorithm;

import java.util.LinkedList;

/**
 * Created by suliucheng on 2021/1/15 23:04
 * Directions: 给你两个非空的链表，表示两个非负的整数。他们每位数字都是按照逆序存储的，并且每个节点只能存储
 * 一位数字。请你将两数相加，并以相同形式返回一个表示和的链表。每个链表长度在1-100内
 * <p>
 * 有如 2,4,3  + 5,6,4 = 7,0,8      243+564=807 逆序存储就是 7,0,8
 */
public class TwoNumsAdd {
    public static void main(String[] args) {
        int[] l1 = {2, 4, 3};
        int[] l2 = {5, 6, 4};
        System.out.println(getTwoNumsAdd(l1, l2));
    }

    private static int getTwoNumsAdd(int[] l1, int[] l2) {
        int numL1 = 0;
        for (int i = 0; i < l1.length; i++) {
            numL1 = (int) (numL1 + l1[i] * Math.pow(10, l1.length - i - 1));
        }

        int numL2 = 0;
        for (int i = 0; i < l2.length; i++) {
            numL2 = (int) (numL2 + l2[i] * Math.pow(10, l2.length - i - 1));
        }
        LinkedList<Integer> list = new LinkedList<>();
        int numL3 = numL1 + numL2;
        return numL3;
    }
}
